package com.wx.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wx.model.Users;
import com.wx.service.OrderCheckService;
import com.wx.serviceImpl.OrderCheckServiceImpl;

/**
 * Servlet implementation class OrderCheckServlet
 */
@WebServlet("/servlet/OrderCheckServlet")
public class OrderCheckServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderCheckServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Users u=(Users)session.getAttribute("login");
		String username = u.getUsername();
		String truename = request.getParameter("truename");
		String phone = request.getParameter("phone");
		String home = request.getParameter("home");
		int postcode = Integer.parseInt(request.getParameter("postcode"));
		Users user=new Users();
		user.setUsername(username);
		user.setPhone(phone);
		user.setHome(home);
		user.setTruename(truename);
		user.setPostcode(postcode);
		OrderCheckService orderCheckService=new OrderCheckServiceImpl();
		try {
			System.out.println("postcord:"+postcode);
			orderCheckService.updateUser(user);
			request.getRequestDispatcher("../finally.jsp").forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
